#ifndef __SPI_H
#define __SPI_H

#include "apm32f10x_spi.h"
#include "apm32f10x_eint.h"
#include "timer.h"
#include "utility.h"

#define PIN_SPI_SCSn GPIO_PIN_13
#define PIN_SPI_SCLK GPIO_PIN_14
#define PIN_SPI_MISO GPIO_PIN_15
#define PIN_SPI_MOSI GPIO_PIN_8
#define W5500_INTn GPIO_PIN_9
#define W5500_PMODE0 GPIO_PIN_10
#define W5500_PMODE1 GPIO_PIN_11
#define W5500_PMODE2 GPIO_PIN_12
#define W5500_RST GPIO_PIN_13

#define PORT_SPI_SCSn GPIOB
#define PORT_SPI_SCLK GPIOB
#define PORT_SPI_MISO GPIOB
#define PORT_SPI_MOSI GPIOA

#define SPI_CS_ENABLE PORT_SPI_SCSn->BC = PIN_SPI_SCSn
#define SPI_CS_DISABLE PORT_SPI_SCSn->BSC = PIN_SPI_SCSn

#define SPI_SCLK_LOW (PORT_SPI_SCLK->BC = PIN_SPI_SCLK)
#define SPI_SCLK_HIGH (PORT_SPI_SCLK->BSC = PIN_SPI_SCLK)

#define SPI_MISO_READ (PORT_SPI_MISO->DIN & PIN_SPI_MISO)

#define SPI_MOSI_LOW (PORT_SPI_MOSI->BC = PIN_SPI_MOSI)
#define SPI_MOSI_HIGH (PORT_SPI_MOSI->BSC = PIN_SPI_MOSI)





uint8_t SPI_ReadWriteOneByte(uint8_t TXdata);


void SPI_init(void);


#endif
